<?
	require_once('init.php');
	require_once('dataModel.php');
//	include("imageCrop.php");
	
	include("resize.php");	 
	include("imgsize.php");


	$error = "";
	$msg = "";
	//$fileElementName = 'fileToUpload';
   	$fileElementName =   $_POST["jObjectextname"];
	$jObjectOthervalue =   $_POST["jObjectOther"];
   //echo				"msg: '" . $fileElementName. "'\n";
	if(!empty($_FILES[$fileElementName]['error']))
	{
		switch($_FILES[$fileElementName]['error'])
		{

			case '1':
				$error = '文件过大,上传失败';///'' The uploaded file exceeds the upload_max_filesize directive in php.ini';
				break;
			case '2':
				$error = '文件过大,上传失败';///'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
				break;
			case '3':
				$error = '上传的文件只有部分被上传';///'The uploaded file was only partially uploaded';
				break;
			case '4':
				$error = '没有文件被上传！' ;///'No file was uploaded.';
				break;

			case '6':
				$error = '临时文件夹不存在,上传失败';/// 'Missing a temporary folder';
				break;
			case '7':
				$error = '写入文件时失败' ;///Failed to write file to disk';
				break;
			case '8':
				$error ='上传被被意外终止';/// 'File upload stopped by extension';
				break;
			case '999':
			
			default:
				$error = '未知原因,导致文件上传失败';///'No error code avaiable';
		}
	}
	elseif(empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none')
	{
		$error = '没有文件被上传！' ;///'No file was uploaded..';
	}
	else 
	{
		
//		$pid=substr($jObjectOthervalue,2,strlen($jObjectOthervalue)-2)*1; // str_replace(char(39),'',$jObjectOthervalue);
//		$ipid=$pid;

		$pid=$jObjectOthervalue;


		//if (getActionValueByProductID('count(productid)',$pid)==0) {
		$time = time();	   
		$i= substr(strrev($fileElementName),0,1);
		$logo = $i."_".$time."_".$_FILES[$fileElementName]["name"];
		$logo_temp = $_FILES[$fileElementName]["tmp_name"];
		
		productimage($logo,$pid,$logo_temp); 

		$strSQL = "update goods set pic".$i."='".$logo."' where id='".$pid."' limit 1 ";
		$db = MySQL::getInstance('','r-w'); 
		$DBR=$db->update($strSQL); 
					
		$msg .= $logo;
		
		@unlink($_FILES[$fileElementName]);	
	}		
	
	echo "{";
	echo				"error: '" . $error. "',\n";
	echo				"msg: '" . $msg."'";
	echo "}";
?>
